
import { classList, addInfoclass, updateInfoclass, deleteInfoclass } from '../services/fetch'
import {
    message
} from 'antd';


export default {

    namespace: 'type',
  
    state: {
        classList: []
    },
  
    subscriptions: {
      setup({ dispatch, history }) { 
      } 
    },
  
    effects: {
        /**
         * 获取分类列表
         */
        *classList({ payload }, { call, put }) {  
            let list = yield call(classList);
            if(list.data.code === 200){
                yield put({type: 'saveClassList', data: list.data.data})
            }
        },
        /**
         * 新增分类
         */
        *addInfoclass({ payload }, { call, put }) {  
            let list = yield call(addInfoclass,payload);
            if(list.data.code === 200){
                message.success(list.data.msg)
                yield put({type: 'classList'})
            }else{
                message.error(list.data.msg)
            }
        },
        /**
         * 修改分类
         */
        *updateInfoclass({ payload }, { call, put }) {  
            let list = yield call(updateInfoclass,payload);
            if(list.data.code === 200){
                message.success(list.data.msg)
                yield put({type: 'classList'})
            }else{
                message.error(list.data.msg)
            }
        },
         /**
         * 删除分类
         */
        *deleteInfoclass({ payload }, { call, put }) {  
            let list = yield call(deleteInfoclass,payload);
            if(list.data.code === 200){
                message.success(list.data.msg)
                yield put({type: 'classList'})
            }else{
                message.error(list.data.msg)
            }
        },
    },
  
    reducers: {
        saveClassList(state, action) {
            return { ...state, classList: action.data };
        },
    },
  };
  